package com.jungle.mvvm.sample.http;

import com.jungle.mvvm.net.BaseNetwork;
import com.trello.rxlifecycle2.LifecycleProvider;

import io.reactivex.ObservableTransformer;
import io.reactivex.Observer;
import okhttp3.Interceptor;

/**
 * 详细说明
 *
 * @author Daniel
 * @version V1.0
 * @date 2020/12/25 17:36
 */
public class WanNetwork extends BaseNetwork {
    private static volatile WanNetwork instance;

    private static WanNetwork getInstance() {
        if (instance == null) {
            synchronized (WanNetwork.class) {
                if (instance == null) {
                    instance = new WanNetwork();
                }
            }
        }
        return instance;
    }

    public static <T> T getService(Class<T> service) {
        return getInstance().getRetrofit(service).create(service);
    }

    public static <T> ObservableTransformer<T, T> applyService(LifecycleProvider lifecycleProvider, Observer<T> observer) {
        return getInstance().applySchedulers(lifecycleProvider, observer);
    }

    @Override
    public String getDev() {
        return "https://www.wanandroid.com/";
    }

    @Override
    public String getTest() {
        return "https://www.wanandroid.com/test/";
    }

    @Override
    public String getProd() {
        return "https://www.wanandroid.com/prod/";
    }

    @Override
    protected Interceptor getInterceptor() {
        return new CookieInterceptor();
    }
}
